

/*!<Includes */
#include <stdio.h>
#include <string.h>
#include "hid_transfer.h"
#include "BSP_Sleep.h"
#include "KeyBoardMap.h"

extern uint8_t  hid_send (uint8_t *report, uint16_t len);

int HID_KB_ReportKeyEvent(uint8_t keyEvent, uint8_t shift){
	static uint8_t report[8] = {0};
	
	report[0] = shift ? 0x02 : 0x00;
	report[2] = keyEvent;
	
	return hid_send(report, sizeof(report));
}

static int HID_KB_ReportKey(uint8_t key, uint8_t shift){
	int ret;
	ret = HID_KB_ReportKeyEvent(key, shift); //key down
	if(ret){
		return ret;
	}
	BSP_Sleep_Ms(2);
	ret = HID_KB_ReportKeyEvent(0, 0); //key up
	BSP_Sleep_Ms(2);
	return ret;
}

void HID_KB_Enter(void){
	HID_KB_ReportKey(0x28, 0);
}

void HID_KB_SendKey(uint8_t key){
	int shift = 0;
	int code = KeyMap_ValueToCode(key, &shift);
	if(code < 0){
		return;
	}
	HID_KB_ReportKey(code, shift);
}



